import { Component, OnInit } from '@angular/core';
import { Store } from '@ngxs/store';
import { Navigate } from '@ngxs/router-plugin';
import { GoodsService } from '../goods.service';
import { Shop } from '../goods.model';

@Component({
  selector: 'app-list',
  templateUrl: './list.component.html',
  styleUrls: ['./list.component.scss'],
})
export class ListComponent implements OnInit {
  listOfData: Shop[] = [];

  constructor(
    private store: Store,
    private service: GoodsService,
  ) {
  }

  ngOnInit(): void {
    this.load();
  }

  load() {
    this.service.shopList().subscribe(r => {
      this.listOfData = r;
    });
  }

  gotoDetails(item: Shop) {
    this.store.dispatch(new Navigate(['/goods/details', item.id]));
  }

  gotoStore(item: Shop) {
    this.store.dispatch(new Navigate(['/goods/store', item.id]));
  }
}
